package com.ruoyi.web.controller.background;

import com.ruoyi.background.domain.AppSiteTopic;
import com.ruoyi.background.service.IAppSiteTopicService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 站点题目Controller
 *
 * @author susu
 * @date 2024-08-27
 */
@RestController
@RequestMapping("/applet/siteTopic")
public class AppSiteTopicController extends BaseController {
    @Autowired
    private IAppSiteTopicService appSiteTopicService;

    /**
     * 查询站点题目列表
     */
    @PreAuthorize("@ss.hasPermi('applet:siteTopic:list')")
    @GetMapping("/list")
    public TableDataInfo list(AppSiteTopic appSiteTopic) {
        startPage();
        List<AppSiteTopic> list = appSiteTopicService.selectAppSiteTopicList(appSiteTopic);
        return getDataTable(list);
    }

    /**
     * 导出站点题目列表
     */
    @PreAuthorize("@ss.hasPermi('applet:siteTopic:export')")
    @Log(title = "站点题目", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AppSiteTopic appSiteTopic) {
        List<AppSiteTopic> list = appSiteTopicService.selectAppSiteTopicList(appSiteTopic);
        ExcelUtil<AppSiteTopic> util = new ExcelUtil<AppSiteTopic>(AppSiteTopic.class);
        util.exportExcel(response, list, "站点题目数据");
    }

    /**
     * 获取站点题目详细信息
     */
    @PreAuthorize("@ss.hasPermi('applet:siteTopic:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(appSiteTopicService.selectAppSiteTopicById(id));
    }

    /**
     * 新增站点题目
     */
    @PreAuthorize("@ss.hasPermi('applet:siteTopic:add')")
    @Log(title = "站点题目", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AppSiteTopic appSiteTopic) {
        return toAjax(appSiteTopicService.insertAppSiteTopic(appSiteTopic));
    }

    /**
     * 修改站点题目
     */
    @PreAuthorize("@ss.hasPermi('applet:siteTopic:edit')")
    @Log(title = "站点题目", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AppSiteTopic appSiteTopic) {
        return toAjax(appSiteTopicService.updateAppSiteTopic(appSiteTopic));
    }

    /**
     * 删除站点题目
     */
    @PreAuthorize("@ss.hasPermi('applet:siteTopic:remove')")
    @Log(title = "站点题目", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(appSiteTopicService.deleteAppSiteTopicByIds(ids));
    }
}
